#include<cstdio>
#include<cstring>
#include<deque>
using namespace std;
const int MX = 30010;
const int NX = 5010;

struct edge{
    int x, y, w, pre;
}e[MX];
int n, elen, last[NX], d[NX], dd[NX];
bool v[NX];
void ins(int x, int y, int w) {
    e[++elen] = edge{x, y, w, last[x]};
    last[x] = elen;
}

void spfa() {
    deque<int> dq;
    dq.push_back(1);
    d[1] = 0;
    dd[1] = 1;
    while(!dq.empty()) {
        int x = dq.front();
        for(int k=last[x]; k; k=e[k].pre) {
            int y = e[k].y;
            if(d[y] > d[x] + e[k].w) {
                d[y] = d[x] + e[k].w;
				dd[y] = dd[x] + 1;
				if(dd[y] > n) {
					printf("YES\n");
					return ;
				}
                if(!v[y]) {
                    v[y] = true;
					dq.push_back(y);
                }
            }
        }
		dq.pop_front();
		v[x] = false;
    }
    if(d[1] < 0)    printf("YES\n");
    else            printf("NO\n");
}

int main() {
    int f;
    scanf("%d", &f);
    while(f--) {
        elen = 0;
        memset(last, 0, sizeof(last));
        memset(d, 0x3f, sizeof(d));
        memset(dd, 0, sizeof(dd));
        memset(v, false, sizeof(v));
        int m, w, a, b, d;
        scanf("%d%d%d", &n, &m, &w);
        while(m--) {
            scanf("%d%d%d", &a, &b, &d);
            ins(a, b, d);
            ins(b, a, d);
        }
        while(w--) {
            scanf("%d%d%d", &a, &b, &d);
            ins(a, b, -d);
        }
        spfa();
    }
    return 0;
}